home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / unix / bsd / ultrix4 / mips / start.S < prev    next >
Encoding:
Text File  |  1994-07-18  |  2.0 KB  |  79 lines

  1. /* Copyright (C) 1993 Free Software Foundation, Inc.
  2.    Contributed by Brendan Kehoe (brendan@zen.org).
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <sysdep.h>
  20.  
  21. #ifndef HAVE_GNU_LD
  22. #define __environ environ
  23. #endif
  24.  
  25. .comm __environ,    4
  26. .comm errno,        4
  27.  
  28. ENTRY(__start)
  29.   .set noreorder
  30.  
  31.   /* The first thing on the stack is argc.  */
  32.   lw t0, 0(sp)
  33.   nop
  34.  
  35.   /* Set up the global pointer.  */
  36.   la gp, _gp
  37.  
  38.   /* Then set up argv.  */
  39.   addiu t1, sp, 4
  40.  
  41.   /* To compute where envp is, first we have to jump ahead four
  42.      bytes from what argv was.  This will bring us ahead, so we don't
  43.      need to compute the NULL at the end of argv later.  */
  44.   addiu v1, t1, 4
  45.  
  46.   /* Now, compute the space to skip given the number of arguments
  47.      we've got.  We do this by multiplying argc by 4.  */
  48.   sll v0, t0, 2
  49.  
  50.   /* Now, add (argv+4) with the space to skip...that's envp.  */
  51.   addu v1, v1, v0
  52.   move t2, v1
  53.  
  54.   /* __environ = envp; */
  55.   sw t2, __environ
  56.  
  57.   addiu sp, sp, -24
  58.  
  59.   /* __libc_init (argc, argv, envp); */
  60.   move a0, t0
  61.   move a1, t1
  62.   move a2, t2
  63.   jal __libc_init
  64.   nop
  65.  
  66.   /* errno = 0; */
  67.   sw zero, errno
  68.  
  69.   /* exit (main (argc, argv, envp)); */
  70.   move a0, t0
  71.   move a1, t1
  72.   move a2, t2
  73.   jal main
  74.   nop
  75.  
  76.   /* Make the value returned by main be the argument to exit.  */
  77.   jal exit
  78.   move a0, v0
  79.